/**
 * 
 * 屏幕管理
 * 
 */
class ScreenLayer extends egret.DisplayObjectContainer {
    /** 创建开场动画的屏幕容器 */
    private openAnimation: egret.DisplayObjectContainer = new egret.DisplayObjectContainer();
    /** 创建开场动画照片 */
    private photo: Photo = new Photo();
    /** 创建开场动画相机 */
    private camera: Camera = new Camera();
    /** 创建地图 */
    private map: MapItem = new MapItem();
    /** 加载弹窗按钮数据 */
    private btnData: Object[] = RES.getRes("btnPathData_json");
    /** 创建弹窗按钮 */
    private alertBtn: DrawBtn = new DrawBtn(this.btnData);
    /** bgm开关 */
    private bgmOff = false;
    /** 加载bgm */
    private bgm = RES.getRes("bgm_mp3");

    public constructor() {
        super();
        this.once(egret.Event.ADDED_TO_STAGE, this.init, this);
    }

    
    private init(): void {
        ///////// test ///////////
        // this.addChild(this.map); // test
        // this.map.addChild(this.alertBtn); // test
        ////////////////////////

        this.addChild(this.openAnimation);
        this.openAnimation.addChild(this.photo);
        this.openAnimation.addChild(this.camera);

        /** 监听相机按钮分发事件 */
        this.camera.addEventListener("camera_btn_down", () => {
            this.photo.isMove = true;

            if (this.bgmOff) return;
            this.bgm.play();
            this.bgmOff = true;

        }, this);
        this.photo.addEventListener("one_wait", () => this.camera.tip_png.visible = true, this);
        this.photo.addEventListener("photo_over", this.switchScreen, this);
    }

    private switchScreen(): void {
        egret.Tween.get(this.openAnimation).to({ alpha: 0 }, 800).call(() => this.removeChild(this.openAnimation));
        this.addChild(this.map);
        this.map.addChild(this.alertBtn);
    }
}